<?php
	include "db.php";
	if(isset($_GET['table'])) $table = $_GET['table'];
	else $table = "";
	$q = "show tables from $db";
	$rs = mysql_query($q);
	echo "<form action='#'>
		<select name='table'>";
	while(($result = mysql_fetch_row($rs))) {
		echo "
			<option value=$result[0]> $result[0] </option>";
		}
		echo "</select>";
		echo "
			<input type='submit' /></form>
		";
		
		$q1 = "select * from $table order by id DESC";
		$rs1 = mysql_query($q1);
		if(mysql_num_rows($rs1)==0) {
			echo "Table : $table<br>";
			echo "No records found";
		}
		echo "<table border>";
		while($row1=mysql_fetch_array($rs1)) {
			$count = mysql_num_fields($rs1);
			$i = $count;
			echo "<form action='update.php' method='post'> <tr>";
					while($count>0)  {
						echo"<td> <input type='text' value='".$row1[$i-$count]."' name = 'a".($i-$count)."'/>";	
						$count--;
					}
					$id = $row1[0];
					echo "
						<td> <input type='submit' name='update' value='Update'/> </a> </td>
						<input type='hidden' name='table' value='$table'/>
						<td> <a href='delete.php?table_name=$table&id=$id'> Delete </a> </td>
					";
			echo "</tr></form>";
		}
		echo"</table>";
?>
